﻿using System;
using System.Data;
using System.Collections.Generic;
using el.Model;
using el.DAL;

namespace el.BLL
{
    /// <summary>
    /// Sys_Role
    /// </summary>
    public partial class Sys_Role
    {
        private readonly el.DAL.Sys_Role dal = new el.DAL.Sys_Role();
        public Sys_Role()
        { }
        #region  Method

        public int UpdateAccess(string rightstr, int RoleID)
        {
            string sql = " update dbo.Sys_Role set Access='" + rightstr + "' where RoleID=" + RoleID.ToString();

            return DbHelperSQL.ExecuteSql(sql);
        }

        public bool CheckAccess(string righstr, int UserID)
        {
            return true;
        }

        public string GetAccess(int RoleID)
        {
            string sql = " select Access from dbo.Sys_Role  where RoleID=" + RoleID.ToString();

            return DbHelperSQL.Query(sql).Tables[0].Rows[0][0].ToString();
        }


        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录

        /// </summary>
        public bool Exists(int RoleID)
        {
            return dal.Exists(RoleID);
        }

        /// <summary>
        /// 增加一条数据

        /// </summary>
        public int Add(el.Model.Sys_Role model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据

        /// </summary>
        public bool Update(el.Model.Sys_Role model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据

        /// </summary>
        public bool Delete(int RoleID)
        {

            return dal.Delete(RoleID);
        }
        /// <summary>
        /// 删除一条数据

        /// </summary>
        public bool DeleteList(string RoleIDlist)
        {
            return dal.DeleteList(RoleIDlist);
        }

        /// <summary>
        /// 得到一个对象实体

        /// </summary>
        public el.Model.Sys_Role GetModel(int RoleID)
        {

            return dal.GetModel(RoleID);
        }

        ///// <summary>
        ///// 得到一个对象实体，从缓存中
        ///// </summary>
        //public el.Model.Sys_Role GetModelByCache(int RoleID)
        //{

        //    string CacheKey = "Sys_RoleModel-" + RoleID;
        //    object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = dal.GetModel(RoleID);
        //            if (objModel != null)
        //            {
        //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch{}
        //    }
        //    return (el.Model.Sys_Role)objModel;
        //}

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据

        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<el.Model.Sys_Role> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<el.Model.Sys_Role> DataTableToList(DataTable dt)
        {
            List<el.Model.Sys_Role> modelList = new List<el.Model.Sys_Role>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                el.Model.Sys_Role model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new el.Model.Sys_Role();
                    if (dt.Rows[n]["RoleID"] != null && dt.Rows[n]["RoleID"].ToString() != "")
                    {
                        model.RoleID = int.Parse(dt.Rows[n]["RoleID"].ToString());
                    }
                    if (dt.Rows[n]["RoleName"] != null && dt.Rows[n]["RoleName"].ToString() != "")
                    {
                        model.RoleName = dt.Rows[n]["RoleName"].ToString();
                    }
                    if (dt.Rows[n]["Description"] != null && dt.Rows[n]["Description"].ToString() != "")
                    {
                        model.Description = dt.Rows[n]["Description"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

